<html>
<head><meta charset="utf-8"><title>How to detect whether a specific lint is `allow`ed? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html">How to detect whether a specific lint is `allow`ed?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195799699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195799699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195799699">(Apr 30 2020 at 05:25)</a>:</h4>
<p>Hello, there's some compute-heavy calculation within <a href="https://github.com/rust-lang/rust/pull/71542" title="https://github.com/rust-lang/rust/pull/71542">one of the lints</a>, which i am working on, and i want to skip the calculation if the lint is <code>allow</code>-ed. I wonder what's the proper way to do this detection? Thanks!</p>



<a name="195831469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195831469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195831469">(Apr 30 2020 at 12:27)</a>:</h4>
<p>Clippy has a helper for it: <a href="https://github.com/rust-lang/rust-clippy/blob/9a3b0a05888f7ad002b67bbe61739695967ce929/clippy_lints/src/utils/mod.rs#L1069" title="https://github.com/rust-lang/rust-clippy/blob/9a3b0a05888f7ad002b67bbe61739695967ce929/clippy_lints/src/utils/mod.rs#L1069">https://github.com/rust-lang/rust-clippy/blob/9a3b0a05888f7ad002b67bbe61739695967ce929/clippy_lints/src/utils/mod.rs#L1069</a></p>



<a name="195831532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195831532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195831532">(Apr 30 2020 at 12:28)</a>:</h4>
<p>I think you can just copy it to your code, as that one liner is probably not useful to be copied to rustc</p>



<a name="195837241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195837241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195837241">(Apr 30 2020 at 13:21)</a>:</h4>
<p>Thanks! I'm working with an early ctx lint though, but it's similar. i think i've worked my way out. I just need to extract a method within <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_lint/levels.rs" title="https://github.com/rust-lang/rust/blob/master/src/librustc_lint/levels.rs">https://github.com/rust-lang/rust/blob/master/src/librustc_lint/levels.rs</a> .</p>



<a name="195905296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905296">(Apr 30 2020 at 21:38)</a>:</h4>
<p>don't lints automatically get that?</p>



<a name="195905342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905342">(Apr 30 2020 at 21:39)</a>:</h4>
<p>like, I thought the entire point of <code>declare_lint_pass!</code> was to only run the pass if the lint is enabled</p>



<a name="195905535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905535">(Apr 30 2020 at 21:41)</a>:</h4>
<p>no, we always run all lint passes, the association with the lints they emit isn't actually used at all</p>



<a name="195905552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905552">(Apr 30 2020 at 21:41)</a>:</h4>
<p>well, it's how those lints get registered</p>



<a name="195905559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905559">(Apr 30 2020 at 21:41)</a>:</h4>
<p>but we could just as easily have them separate</p>



<a name="195905624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/195905624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#195905624">(Apr 30 2020 at 21:42)</a>:</h4>
<p>and you can totally emit other lint passes' lints from your lint pass</p>



<a name="196051946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/196051946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#196051946">(May 02 2020 at 13:34)</a>:</h4>
<p>oh</p>



<a name="196055436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/196055436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#196055436">(May 02 2020 at 15:01)</a>:</h4>
<p>to be clear, I think this is probably a "bug" at some level, we should perhaps fix it</p>



<a name="196055476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/How%20to%20detect%20whether%20a%20specific%20lint%20is%20%60allow%60ed%3F/near/196055476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/How.20to.20detect.20whether.20a.20specific.20lint.20is.20.60allow.60ed.3F.html#196055476">(May 02 2020 at 15:02)</a>:</h4>
<p>rustc actually merges all lint passes IIRC into one for performance reasons</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>